package com.cysion.study.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.cysion.study.ktbox.base.BaseAdapter
import com.cysion.study.ktbox.base.BaseViewHolder
import com.cysion.study.ktbox.image.RoundTransform
import com.cysion.study.R
import com.cysion.study.entity.CommentsEntity
import kotlinx.android.synthetic.main.item_comments.view.iv_head
import kotlinx.android.synthetic.main.item_comments.view.tv_content
import kotlinx.android.synthetic.main.item_comments.view.tv_title
import kotlinx.android.synthetic.main.item_comments_chat.view.*

class CommentsChatAdapter(mEntities: MutableList<CommentsEntity>, mContext: Context) :
    BaseAdapter<CommentsEntity>(mEntities, mContext) {

    companion object {

        //点击事件
        const val refuse = 2000
        const val agree = 2001
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<CommentsEntity> {
        return ProMoneyHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_comments_chat, parent, false)
        )
    }

    class ProMoneyHolder(itemView: View) : BaseViewHolder<CommentsEntity>(itemView) {
        override fun fillData(obj: CommentsEntity, position: Int) {
            itemView?.apply {
                //                itemView.tv_data.text=
                //0.教师(自己) 1.家长(发送信息人)
                if (obj.fromUserType == "0") {
                    iv_head.visibility=View.INVISIBLE
                    tv_title.visibility=View.INVISIBLE
                    iv_rhead.visibility=View.VISIBLE
                    tv_rtitle.visibility=View.VISIBLE

                    tv_rtitle.text = obj.userName
                    Glide.with(context)
                        .load(obj.userHeadImageUrl)
                        .apply(RequestOptions.placeholderOf(R.mipmap.place_holder_big))
                        .apply(RequestOptions.bitmapTransform(RoundTransform(6)))
                        .into(iv_rhead)
                }else if (obj.fromUserType == "1") {
                    iv_head.visibility=View.VISIBLE
                    tv_title.visibility=View.VISIBLE
                    iv_rhead.visibility=View.INVISIBLE
                    tv_rtitle.visibility=View.INVISIBLE
                    Glide.with(context)
                        .load(obj.fromUserHeadImageUrl)
                        .apply(RequestOptions.placeholderOf(R.mipmap.place_holder_big))
                        .apply(RequestOptions.bitmapTransform(RoundTransform(6)))
                        .into(iv_head)
                }
                tv_content.text = obj.content


            }
        }

    }
}